<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Set"%>
<%@page import="com.taobao.askwho.vo.PersonalPageRecordVo"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="快速找到解决问题的人或资料的网站">
<meta name="author" content="zhongting.zy">
<title>我的主页</title>
<!-- Le styles -->
<link href="<%= request.getContextPath()%>/assets/css/bootstrap.css"
	rel="stylesheet">
<style type="text/css">
body {
	padding-top: 60px;
	padding-bottom: 40px;
}
</style>
<link
	href="<%=request.getContextPath()%>/assets/css/bootstrap-responsive.css"
	rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon"
	href="<%= request.getContextPath()%>/assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-57-precomposed.png">
</head>
<%
	List<PersonalPageRecordVo> itemList = (List<PersonalPageRecordVo>)request.getAttribute("itemList");
	if(itemList == null)
		itemList = new ArrayList<PersonalPageRecordVo>();
	
	String otherUuid = (String)request.getAttribute("otherUuid");
	String myUuid = (String)request.getAttribute("myUuid");
	boolean isDistabledShareButton = false;
	if(otherUuid == null || myUuid == null || (otherUuid.equals(myUuid))) {
		isDistabledShareButton = true;	//信息不全，不能分享
	}
%>
<body>
	<%@include file="/jsp/header.jsp" %>
	<div class="container">
		<div class="row">
			<div class="span12">
				<h3 align="center">${originusername}的分享</h3>
				<div style="float: right;">
					<%
						if(isDistabledShareButton) {
					%>
					<button class="btn btn-small btn-primary" disabled="disabled" title="不能收藏自己的信息">加入我的收藏</button>
					<%
						} else {
					%>
					<form action="<%=request.getContextPath()%>/tagopt.do" method="post">
						<input type="hidden" name="method" value="collectOtherTags">
						<input type="hidden" id="myUuid" name="myUuid" value="${myUuid}">
						<input type="hidden" id="otherUuid" name="otherUuid" value="${otherUuid}">
						<button class="btn btn-small btn-primary" type="submit">加入我的收藏</button>
					</form>	
					<%							
						}
					%>
					
				</div>
				<table class="table table-striped">
					<thead>
						<tr>
							<th width="50%">内容</th>
							<th width="10%">类型</th>
							<th width="10%">权限</th>
							<th width="30%">已有的标签</th>
						</tr>
					</thead>
					<tbody>
					<%
						for(PersonalPageRecordVo vo : itemList) {
							String content = "";
							String type = vo.getType(); 
							if(type.equals("url")) {
								content = vo.getUrlInfo().getUrlContent();
							} else {
								content = vo.getPersonInfo().getPersonName() 
										+ "(旺旺:" + vo.getPersonInfo().getWangwang() + ")";
							}
							Set<String> set = vo.getTagNamesSet();
							String tagLinkContent = "";
							for(String tagName : set) {
								tagLinkContent +="<a href='#'>" + tagName + "</a>&nbsp;&nbsp;";
							}
							String isPublic = "";
							if(vo.isPublic())
								isPublic = "公开";
							else
								isPublic = "私有";
							String tagIds = vo.getTagUuidsString();
					%>
						<tr>
							<td><%=content%></td>
							<td><%=vo.getType()%></td>
							<td><%=isPublic%></td>
							<td><%=tagLinkContent%></td>
						</tr>						
					<%
						}
					%>
					</tbody>
				</table>
			</div>
		</div>
		<!--/row-->
		<hr>
	<%@include file="/jsp/footer.jsp" %>
	</div>
	<!--/.fluid-container-->

	<!-- Le javascript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="<%=request.getContextPath()%>/assets/js/jquery.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-transition.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-alert.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-modal.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-dropdown.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-scrollspy.js"></script>
	<script src="<%=request.getContextPath()%>/assets/js/bootstrap-tab.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-tooltip.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-popover.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-button.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-collapse.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-carousel.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-typeahead.js"></script>
	<script>
		$(function() {
			//$('#myTab a[href="#url"]').tab('show');
			
			$('#myTab a').click(function (e) {
				  e.preventDefault();
				  var nodeValue = $(this)[0].attributes[0].nodeValue;
				  if(nodeValue == "#url") {
					  $('#curentType').attr("value", "url");
				  } else {
					  $('#curentType').attr("value", "person");
				  }
				  $(this).tab('show');
			})
			
			//show,shown,hide,hidden  四个状态
			$('#myModal').on('show', function () {
				//理想情况进来时都是显示添加URL界面，目前暂未实现
			})
			$('#myModal').on('hidden', function () {
				$('#urlform')[0].reset();
				$('#personform')[0].reset();
			})
			//点击添加窗口的添加表单
			$("#btnSaveNew").click(function() {
				
				var type = $("#urlContent").val();
				var curentType = $("#curentType").val();
				if(curentType == "url") {
					$.ajax({
						  url: '<%=request.getContextPath()%>/urlopt.do?method=addNewUrl',
						  dataType: 'json',
						  type: "post",
						  data: {
							  urlContent: $("#urlContent").val(),
							  isPublic: $("#isPublicUrl").val(),
							  tagString: $("#tagStringUrl").val(),
							  userUuid: $("#userUuid").val()
						  },
						  success: function(data) {
							if(data.success) {
								//alert("保存成功");
								$('#myModal').modal('hide');
								window.location.reload();
							} else {
								//alert(data.msg);
								alert("保存失败");
							}
						  }
						});					
				} else {	//person
					$.ajax({
						  url: '<%=request.getContextPath()%>/personopt.do?method=addNewPerson',
						  dataType: 'json',
						  type: "post",
						  data: {
							  personName: $("#personName").val(),
							  wangwang: $("#wangwang").val(),
							  tagString: $("#tagStringPerson").val(),
							  isPublic: $("#isPublicPerson").val(),
							  userUuid: $("#userUuid").val()
						  },
						  success: function(data) {
							if(data.success) {
								//alert("保存成功");
								$('#myModal').modal('hide');
								window.location.reload();
							} else {
								//alert(data.msg);
								alert("保存失败");
							}
						  }
						});					
				}
				return true;
			});	
		})
		function deleteByUuids(ids,type) {
			$.ajax({
				  url: '<%=request.getContextPath()%>/tagopt.do?method=deleteByTagUuids',
				  dataType: 'json',
				  type: "post",
				  data: {
					  tagUuids: ids,
					  type: type
				  },
				  success: function(data) {
					if(data.success) {
						//alert("删除成功");
						window.location.reload();
					} else {
						alert(data.msg);
						//alert("保存失败");
					}
				  }
				});				
		}
	</script>
</body>
</html>
